package cn.java.exercises;

public class Loop
{
    public static void main(String[] args)
    {
        //打印菱形
        //打印等腰三角形
        System.out.println("--------for循环实现-----------");
        int nLine=4;
        for (int i = 1; i <= nLine; i++)
        {
            for (int j = nLine; j >i; j--)
            {
                System.out.print(" ");
            }
            for (int j = 0; j <2*i-1 ; j++)
            {
                System.out.print("*");
            }
            System.out.println("");

        }
        //打印等腰倒三角形
        nLine=3;
        for (int i = 1; i <= nLine; i++)
        {
            for (int j = 0; j < i; j++)
            {
                System.out.print(" ");
            }
            for (int j = 2*(nLine-i+1)-1; j >0 ; j--)
            {
                System.out.print("*");
            }
            System.out.println("");
        }

        //打印菱形，中间十字
        System.out.println("--------while循环实现-----------");
        nLine=4;
        int i=1,j;
        while (i <= nLine)
        {
            j = nLine;
            while(j > i)
            {
                System.out.print(" ");
                j--;
            }
            j=0;
            while (j <2*i-1 )
            {
                if(i == 4 && j==3)
                    System.out.print("+");
                else
                    System.out.print("*");
                j++;
            }
            System.out.println("");
            i++;
        }

        nLine=3;
        i=1;
        while(i <= nLine)
        {
            j=0;
            while (j < i)
            {
                j++;
                System.out.print(" ");
            }
            j=2*(nLine-i+1)-1;;
            while (j >0)
            {
                j--;
                System.out.print("*");
            }
            System.out.println("");
            i++;
        }

    }
}
